﻿using SimpleConnection_UDP_WIN.extension_class.utils;
using SimpleConnection_UDP_WIN.interface_class;
using SimpleConnection_UDP_WIN.utils.UDP;
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsImageCompressionApp.utils;

namespace SimpleConnection_UDP_WIN.extension_class.form_ui
{
    internal class ShowDialogClass : PluginAbstractClass, PluginBaseInfoInterface
    {
        //传入命令的关键协议名
        public const string Protocol = "dialog";

        public ShowDialogClass()
        {
        }

        public ShowDialogClass(string message, string ip, int port) : base(message, ip, port)
        {
            this.message = message;
            this.ip = ip;
            this.port = port;
        }

        public string Name => "弹窗类";
        public string Describe => "让计算机弹出信息框";
        public string Version => "1.1.0";
        public string Help => "示例:dialog://<key>标题<key><string>内容<string>\n<num>[0-5]</num>表示图标类型";

        /// <summary>
        /// 主要执行方法
        /// </summary>
        public void exec()
        {
       
            if (MessageParsingClass.isAdmin(message))
            {

               

                switch (MessageParsingClass.getNum(message))
                {
                    case 0:
                        Task.Run(() => {
                            MessageBox.Show(MessageParsingClass.getString(message), MessageParsingClass.getKey(message),
                            MessageBoxButtons.OK);
                        });
                        break;
                    case 1:
                        Task.Run(() => {
                            MessageBox.Show( MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK
                            , MessageBoxIcon.Information);
                        });
                        break;
                    case 2:
                        Task.Run(() => {
                            MessageBox.Show(MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK
                            , MessageBoxIcon.Warning);
                        });
                        break;
                    case 3:
                        Task.Run(() => {
                            MessageBox.Show(MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK
                            , MessageBoxIcon.Error);
                        });
                        break;
                    case 4:
                        Task.Run(() => {
                            MessageBox.Show( MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK
                            , MessageBoxIcon.Question);
                        });
                        break;
                    case 5:
                        Task.Run(() => {
                            MessageBox.Show(MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK
                            , MessageBoxIcon.Stop);
                        });
                        break;
                    case 10:
                 
                            Form topMostForm = new Form
                            {
                                TopMost = true // 将窗体置于最顶层
                            };
                            MessageBox.Show(topMostForm,MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK);
                            topMostForm.Dispose();
                       
                        break;
                    default:
                        Task.Run(() => {
                            MessageBox.Show(MessageParsingClass.getString(message), MessageParsingClass.getKey(message), MessageBoxButtons.OK);
                        });
                        break;
                }
                new UdpTool(ip,8871).SendMessage(GetType().Name,"已弹窗");
            }
        }
    }
}
